package bar;

import java.io.BufferedReader;
import java.io.BufferedWriter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Test {
	public int getMoneyPlay(String phone) throws IOException{
		SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String str ="";
		long d1 = 0L;
		long d2 = 0L;
		File file = new File("net-log.txt");
		FileReader fr = new FileReader(file);
		BufferedReader bf = new BufferedReader(fr);
		while((str = bf.readLine()) != null){
			
			String[] s = str.split(",");
			if(s[0].equals(phone) && s[1].equals("up")){
				try {
					d1 = a.parse(s[2]).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}else if(s[0].equals(phone) && s[1].equals("down")){
				try {
					d2 = a.parse(s[2]).getTime();
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
		}
		double time = ((d2 - d1)/1800.0)/1000;
		return  (int) Math.ceil(time);
	}
}
